<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<script src="<c:url value='/js/courseNewClass.js'/>" type="text/javascript" charset="utf-8"></script> 

<!--添加助教-->

<div class="row">
	<div class="col-md-2 col-lg-2"></div>
	<div class="col-md-8 col-lg-8">
		<div class="form-group">
			<div class="row">
				<div class="col-md-12 col-lg-12" style="margin-top:2rem;text-align:center;">
					<label for="courseName">添加助教</label>
				</div>
			</div>
			<div class="row" style="margin-top:2rem;">
				<div class="col-md-6 col-lg-6">
					<input type="text" class="form-control" name="keywords" placeholder="学号/姓名">
				</div>
				<div class="col-md-6 col-lg-6">
					<button class="btn btn-primary" id="search">搜索</button>
				</div>
			</div>
		</div>
		<table class="table table-hover">
			<thead>
				<tr>
					<th>序号</th>
					<th>学号</th>
					<th>姓名</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody id="seacherData">
				
			</tbody>
		</table>
	</div>
	<div class="col-md-2 col-lg-2"></div>
</div>

<script>
$(function() {
	$("#search").click(function(){
		getAssistantList();
	});
});
var getAssistantList = function() {
	var keywords=$("input[name='keywords']").val();
	if(keywords==""){
		alert("请输入搜索信息");
		return;
	}
	var json={
			keywords:keywords,
			courseId:data.data.course.id
	};
	$.get(CONTEXT_PATH+"accontrol/ajaxListData", {
		data : JSON.stringify(json)
	} ,function(data) {
		if(data.status=="success"){
    		var seacherData =$("#seacherData");
    		seacherData.empty();
    		var s="";
    		for(var i=0;i<data.data.list.length;i++){
    			var item=data.data.list[i];
    			s+="<tr>";
    			s+="<th scope=\"row\">"+(i+1)+"</th>";
    			s+="<td title=\""+item.assistantCode+"\">"+item.assistantCode+"</td>";
    			s+="<td title=\""+item.name+"\">"+item.name+"</td>";
    			if(item.hasJoined==1){
	    			s+="<td><button disabled=\"disabled\" onclick=\"addAssistantToCourse("+item.id+")\" class=\"btn btn-primary\">已添加</button></td>";
    			}else{
	    			s+="<td><button onclick=\"addAssistantToCourse("+item.id+")\" class=\"btn btn-primary\">添加</button></td>";
    			}
    			s+="</tr>"
    		}
    		seacherData.append(s);
		}else{
			alert(data.message);
		}
	}); 
}
var addAssistantToCourse= function(id){
	var json={
			courseId:data.data.course.id,
			assistantId:id
	};
	
	$.post(CONTEXT_PATH+"accontrol/ajaxCreate", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			getAssistantList();
		}else{
			alert(data.message);
		}
	}); 
}
</script>